package com.atguigu.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class ContextServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = getServletConfig().getServletContext();

        String username = context.getInitParameter("username");
        System.out.println("username: " + username);
        System.out.println("password: " + context.getInitParameter("password"));

        System.out.println("path: " + context.getContextPath());

        System.out.println("abs path: " + context.getRealPath("/"));

        context.setAttribute("key1", "value1");
        System.out.println("key1: " + context.getAttribute("key1"));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
